package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/**
 * @param
 * @return
 */
@Api(tags = "护理项目相关接口")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController {
    @Autowired
    NursingProjectService nursingProjectService;

    //分页查询所有数据
    @ApiOperation(value = "分页查询接口")
    @GetMapping
    @ApiImplicitParams({
            @ApiImplicitParam(value = "护理项名称", name = "name", dataType = "string"),
            @ApiImplicitParam(value = "启用状态", name = "status", dataType = "string"),
            @ApiImplicitParam(value = "页码", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "每页显示条数", name = "pageSize", required = true, dataType = "int")})
    public ResponseResult selectByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageResponse page = nursingProjectService.selectByPage(name, pageNum, pageSize, status);
        return success(page);
    }

    //新增护理项目
    @ApiOperation(value = "新增护理项目接口")
    @PostMapping
    public ResponseResult insertNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.insertNursingProject(nursingProjectDto);
        return success();
    }

    //查询回显
    @ApiOperation(value = "根据id查询回显护理项目")
    @GetMapping("/{id}")
    public ResponseResult selectByIdProject(@PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.selectNursingProjectById(id);
        return success(nursingProjectVo);
    }

    //修改护理项目
    @ApiOperation(value = "修改护理项目")
    @PutMapping
    public ResponseResult selectNursingProgect(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    //删除护理项目
    @ApiOperation(value = "删除护理项目")
    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingProject(@PathVariable Long id) {
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    //是否禁用
    @ApiOperation(value = "是否禁用该护理项目")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult isStatusNursingProject(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectService.isStatusNursingProject(id, status);
        return success();

    }

    //查询所有的护理项目,在护理计划中需要查出来
    @ApiOperation(value = "查询所有的护理项目")
    @GetMapping("/all")
    public ResponseResult getAllNursingProject() {
        List<NursingProjectVo> list = nursingProjectService.getAllNursingProject();
        return success(list);
    }

}
